<?php
namespace Admin\Form;
use Common\Form\BaseForm;
use Common\Model\CurrencyModel;
use Common\Model\LeavelRatioModel;
class ConfigForm extends BaseForm {
    public static function newSelf()
    {
        return new self();
    }
    protected $data;
    protected $action;
    protected $return_type;
    public function __construct()
    {
        set_time_limit(0);
        parent::__construct();
        $this->return_type='ajax';
        $this->data['updateCurrencyInfo']=[
            'id1'=>'id1',
            'id2'=>'id2',
            'id3'=>'id3',
            'id4'=>'id4',
            'id5'=>'id5',
            'id6'=>'id6'
        ];
        $this->data['updateLeavelInfo']=[
            'id'=>'id',
            'ratio1'=>'ratio1',
            'ratio2'=>'ratio2',
            'ratio3'=>'ratio3',
            'ratio4'=>'ratio4',
            'ratio5'=>'ratio5',
            'ratio6'=>'ratio6',
            'ratio7'=>'ratio7',
            'ratio8'=>'ratio8'
        ];
    }
    public function updateCurrencyInfo($input)
    {
        $this->action='updateCurrencyInfo';
        $this->__toInitialize($input);
        $data=$this->getAllData();
        $model=CurrencyModel::newSelf();
        $currency=$model->findInfo();
        foreach ($currency as $k=>$v)
        {
            $model->where($v)->setField('reward_ratio',$data['id'.$k]);
        }
        $this->returnResult('修改成功',true);
    }
    public function updateLeavelInfo($input)
    {
        $this->action='updateLeavelInfo';
        $this->__toInitialize($input);
        $this->emptyVerification('id', '请选择等级');
        $data=$this->getAllData();
        
        $model=LeavelRatioModel::newSelf();
        $leavel=$model->getByLeavelId($this->getDataVal('id'));
        foreach ($leavel as $k=>$v)
        {
            $model->where(['id'=>$v['id']])->setField($v['reward_type']['type'],$this->getDataVal('ratio'.$k));
        }
        $this->returnResult('修改成功',true);
    }
    
    
}